#include "sortwidget.h"
#include <QPainter>

sortwidget::sortwidget(QWidget *parent) : QWidget(parent)
{

}

/*重写paint事件*/
void sortwidget::paintEvent(QPaintEvent *)
{
    QPainter painter(this);
    float x, y, p;
    x = (float)1000/size;
    y = x/(float)3;
    p = 0;
    for(int i = 0; i < size; i++)
    {
        if(i <= this->c1 && -10 == this->c2)
        {
            painter.fillRect(QRectF(p,415-array[i],x-y,array[i]),Qt::green);
        }
        else
        {
            if(i == this->c1 || i == this->c2)
            {
                painter.fillRect(QRectF(p,415-array[i],x-y,array[i]),Qt::red);
            }
            else
            {
                painter.fillRect(QRectF(p,415-array[i],x-y,array[i]),Qt::black);
            }
        }
        p += x;
    }
}
